/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cadi.aux;

/**
 *
 * @author ApoZuniga
 */
import static com.cadi.aux.Window.styleMoney;
import static com.cadi.aux.Window.styleText;
import com.cadi.games.SuperEasyLevel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;

/**
 *
 * @author ApoZuniga
 */
public class ItemEasySuper extends Window {
    protected JLabel instruction;
    protected JLabel requiredTotal;
    protected JLabel product;
    private JLabel labelTotal;
    private JLabel userTotal;
    private JButton coinOne;
    private JButton coinTwo;
    private JButton coinThree;
    private JButton coinFour;
    protected double total;
    private double initialMoney;
    protected ActionListener valueListenerOne;
    protected ActionListener valueListenerTwo;
    protected ActionListener valueListenerThree;
    protected ActionListener valueListenerFour;
    private double valueOptionOne = 0.5;
    private double valueOptionTwo = 1;
    private double valueOptionThree = 2;
    private double valueOptionFour = 5;
    
    
    public ItemEasySuper() {
        super();
        initialMoney = 0;
        instruction = new JLabel(" ");
        instruction.setFont(styleText);
        instruction.setBounds(50, -50, 800, 200);
        requiredTotal = new JLabel(" ");
        requiredTotal.setFont(styleMoney);
        requiredTotal.setBounds(300, 0, 500, 300);
        product = new JLabel(new ImageIcon(getClass().getResource("/resources/compra_1.png")));
        product.setBounds(50, 80, 162, 170);
        container.add(product, JLayeredPane.PALETTE_LAYER);
        labelTotal = new JLabel("Llevas pagado: ");
        labelTotal.setFont(styleText);
        labelTotal.setBounds(270, 455, 200, 150);
        userTotal = new JLabel("$ 0" );
        userTotal.setFont(styleMoney);
        userTotal.setBounds(500, 420, 300, 200);
        
        valueListenerOne = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculateTotalActionPerformed(ae, valueOptionOne);
            }
        };
        valueListenerTwo = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculateTotalActionPerformed(ae, valueOptionTwo);
            }
        };
        valueListenerThree = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculateTotalActionPerformed(ae, valueOptionThree);
            }
        };
        valueListenerFour = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculateTotalActionPerformed(ae, valueOptionFour);
            }
        };
        
        coinOne = new JButton(new ImageIcon(getClass().getResource("/resources/50centavos-small.png")));
        coinOne.setBounds(330, 270, 100, 100);
        coinOne.addActionListener(valueListenerOne);
        coinTwo = new JButton(new ImageIcon(getClass().getResource("/resources/1peso-small.png")));
        coinTwo.setBounds(500, 270, 100, 100);
        coinTwo.addActionListener(valueListenerTwo);
        coinThree = new JButton(new ImageIcon(getClass().getResource("/resources/2pesos-small.png")));
        coinThree.setBounds(670, 270, 100, 100);
        coinThree.addActionListener(valueListenerThree);
        coinFour = new JButton(new ImageIcon(getClass().getResource("/resources/5pesos-small.png")));
        coinFour.setBounds(840, 270, 100, 100);
        coinFour.addActionListener(valueListenerFour);
        
        this.container.add(userTotal, JLayeredPane.PALETTE_LAYER);
        this.container.add(labelTotal, JLayeredPane.PALETTE_LAYER);
        this.container.add(requiredTotal, JLayeredPane.PALETTE_LAYER);
        this.container.add(instruction, JLayeredPane.PALETTE_LAYER);
        this.container.add(coinOne, JLayeredPane.PALETTE_LAYER);
        this.container.add(coinTwo, JLayeredPane.PALETTE_LAYER);
        this.container.add(coinThree, JLayeredPane.PALETTE_LAYER);
        this.container.add(coinFour, JLayeredPane.PALETTE_LAYER);
        
        toMenu.setVisible(true);
        window.setVisible(true);
    }
    private void calculateTotalActionPerformed(ActionEvent evt, double valueMoney) {
        initialMoney += valueMoney;
        if (initialMoney < total) {
            userTotal.setText("$ " + String.valueOf(initialMoney));
        } else if (initialMoney == total) {
            userTotal.setText("$ " + String.valueOf(initialMoney));
            result = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                result.play();
            JOptionPane.showMessageDialog(null, "¡Bien Hecho!", "¡Bien Hecho!", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/right.png")));
            SuperEasyLevel superLevel = new SuperEasyLevel();
        } else if (initialMoney > total) {
            result = java.applet.Applet.newAudioClip(getClass().getResource("/resources/mal.wav"));
                result.play();
            JOptionPane.showMessageDialog(null, "Intenta de nuevo", "Intenta de nuevo", JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getClass().getResource("/resources/wrong.png")));
            initialMoney -= valueMoney;
        }
        window.repaint();
    }
}
